﻿// -----------------------------------------------------------------------
// <copyright file="TemplatedHTMLControl.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Metro.GridView
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI;
    using Microsoft.SharePoint.WebControls;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class TemplatedHTMLControl : ITemplate
    {
        private String _DataField;

        public TemplatedHTMLControl(String DataField)
        {
            _DataField = DataField;
        }

        public void InstantiateIn(Control container)
        {
            LiteralControl literalHTML = new LiteralControl();
            literalHTML.DataBinding += new EventHandler(literalHTML_DataBinding);
            container.Controls.Add(literalHTML);

        }

        void literalHTML_DataBinding(object sender, EventArgs e)
        {
            LiteralControl literalHTML = (LiteralControl) sender;
            SPGridViewRow container = (SPGridViewRow) literalHTML.NamingContainer;
            if(_DataField.Length > 0)
            {
                literalHTML.Text += DataBinder.Eval(container.DataItem, _DataField);
            }
        }
    }
}
